﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SystemManage_SystemParamConfig_FtpUpLoadConfig : System.Web.UI.Page
{
    private Model.SYSPARAM SysParam
    {
        get
        {
            Model.SYSPARAM sysParam = null;
            if (ViewState["SysParam"] != null)
            {
                sysParam = (Model.SYSPARAM)ViewState["SysParam"];
            }
            return sysParam;
        }
        set
        {
            ViewState["SysParam"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("100100101");
        if (!IsPostBack)
        {
            this.SysParam = new BLL.SYSPARAM().GetModel("001");
            if (this.SysParam != null)
            {
                chkInitiateFtpUpLoad.Checked = this.SysParam.SP_PARAM1 == 1 ? true : false;
                txtFtpAddress.Text = this.SysParam.SP_PARAM13;
                txtUserName.Text = this.SysParam.SP_PARAM14;

                string[] image1WidthHeight = this.SysParam.SP_PARAM16.Split(',');
                if (image1WidthHeight.Length == 2)
                {
                    txtImage1Width.Text = image1WidthHeight[0];
                    txtImage1Height.Text = image1WidthHeight[1];
                }

                string[] image2WidthHeight = this.SysParam.SP_PARAM17.Split(',');
                if (image2WidthHeight.Length == 2)
                {
                    txtImage2Width.Text = image2WidthHeight[0];
                    txtImage2Height.Text = image2WidthHeight[1];
                }

                string[] image3WidthHeight = this.SysParam.SP_PARAM18.Split(',');
                if (image3WidthHeight.Length == 2)
                {
                    txtImage3Width.Text = image3WidthHeight[0];
                    txtImage3Height.Text = image3WidthHeight[1];
                }

                string[] image4WidthHeight = this.SysParam.SP_PARAM19.Split(',');
                if (image4WidthHeight.Length == 2)
                {
                    txtImage4Width.Text = image4WidthHeight[0];
                    txtImage4Height.Text = image4WidthHeight[1];
                }

                txtFtpUploadPath.Text = this.SysParam.SP_PARAM20;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("100100101", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        if (this.SysParam != null)
        {
            this.SysParam.SP_PARAM1 = chkInitiateFtpUpLoad.Checked ? 1 : 0;
            this.SysParam.SP_PARAM13 = txtFtpAddress.Text.Trim();
            this.SysParam.SP_PARAM14 = txtUserName.Text.Trim();
            if (txtPassword.Text.Trim() != "")
            {
                this.SysParam.SP_PARAM15 = txtPassword.Text.Trim();
            }
            this.SysParam.SP_PARAM16 = txtImage1Width.Text.Trim() + "," + txtImage1Height.Text.Trim();
            this.SysParam.SP_PARAM17 = txtImage2Width.Text.Trim() + "," + txtImage2Height.Text.Trim();
            this.SysParam.SP_PARAM18 = txtImage3Width.Text.Trim() + "," + txtImage3Height.Text.Trim();
            this.SysParam.SP_PARAM19 = txtImage4Width.Text.Trim() + "," + txtImage4Height.Text.Trim();
            this.SysParam.SP_PARAM20 = txtFtpUploadPath.Text.Trim();

            this.SysParam.SP_PARAM9 = DateTime.Now;
            this.SysParam.SP_PARAM10 = DateTime.Now;
            this.SysParam.SP_PARAM11 = DateTime.Now;
            this.SysParam.SP_PARAM12 = DateTime.Now;

            if (new BLL.SYSPARAM().Update(this.SysParam))
            {
                Share.InsertLog("100100101", "00017");
                Response.Write("<script>alert('保存成功');</script>");
            }
            else
            {
                Response.Write("<script>alert('保存失败');</script>");
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("FtpUpLoadConfig.aspx");
    }
}
